Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

Vue.js 學習旅程Mile 13 – List Rendering 列表渲染篇:v-for

Vue.js 學習旅程Mile 13 – List Rendering 列表渲染篇:v-for

用 Python 自學資料科學與機器學習入門實戰:Scikit Learn 基礎入門

用 Python 自學資料科學與機器學習入門實戰:Scikit Learn 基礎入門

[ CSS 05 ] 遮罩裁切相關

[ CSS 05 ] 遮罩裁切相關


Comments